package com.health.viewscontrols.tjbg.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.TimeUtils;
import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.components.AxisBase;
import com.github.mikephil.charting.components.Description;
import com.github.mikephil.charting.components.Legend;
import com.github.mikephil.charting.components.XAxis;
import com.github.mikephil.charting.components.YAxis;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.formatter.IAxisValueFormatter;
import com.github.mikephil.charting.highlight.Highlight;
import com.github.mikephil.charting.listener.OnChartValueSelectedListener;
import com.health.R;
import com.health.httpbean.model.FmModel;
import com.health.tablebean.SBCL_DATA;
import com.health.viewscontrols.NovaApplication;
import com.health.viewscontrols.tjbg.MyMarkerView;
import com.health.viewscontrols.tjbg.base.BaseFragment;
import com.health.viewscontrols.tjbg.bean.XuezhiBean;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
 * author : xiaoxin
 * date   : 2020/12/21 11:52
 * desc   :
 * update :
 */
public class DhRTCFFragment extends BaseFragment  {


    private LinearLayout ll_root;
    private TextView tv_height;
    private TextView tv_weight;
    private TextView tv_bmi;
    private TextView tv_tzfl;
    private TextView tv_yxsy;
    private TextView tv_nzzfdj;
    private TextView tv_tsfl;
    private TextView tv_sm;
    private TextView tv_ecf;
    private TextView tv_icf;
    private TextView tv_proteinRate;
    private TextView tv_bmr;
    private TextView tv_ewr;
    private TextView tv_bodyScore;

    private TextView tv_tjbg_no_data;
    String strWhere = "IDCARD = '" + NovaApplication.getUserInfo().getIDCARD() + "'";

    public static DhRTCFFragment newInstance() {

        DhRTCFFragment fragment = new DhRTCFFragment();
        Bundle args = new Bundle();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected int getContentViewLayoutID() {
        return R.layout.fragment_rtcf_dh;
    }

    @Override
    protected void initView(View view) {
        ll_root = view.findViewById(R.id.ll_root);
        tv_height = view.findViewById(R.id.tv_height);
        tv_weight = view.findViewById(R.id.tv_weight);
        tv_bmi = view.findViewById(R.id.tv_bmi);
        tv_tzfl = view.findViewById(R.id.tv_tzfl);
        tv_yxsy = view.findViewById(R.id.tv_yxsy);
        tv_nzzfdj = view.findViewById(R.id.tv_nzzfdj);
        tv_tsfl = view.findViewById(R.id.tv_tsfl);
        tv_sm = view.findViewById(R.id.tv_sm);
        tv_ecf = view.findViewById(R.id.tv_ecf);
        tv_icf = view.findViewById(R.id.tv_icf);
        tv_proteinRate = view.findViewById(R.id.tv_proteinRate);
        tv_bmr = view.findViewById(R.id.tv_bmr);
        tv_ewr = view.findViewById(R.id.tv_ewr);
        tv_bodyScore = view.findViewById(R.id.tv_bodyScore);
        tv_tjbg_no_data = view.findViewById(R.id.tv_tjbg_no_data);
    }

    @Override
    protected void initData() {
        try {
            List<SBCL_DATA> list1 = NovaApplication.fdbmanger.findAllByWhere(SBCL_DATA.class,
                    strWhere + " AND CL_TYPE = 'RTCF_DH' ORDER BY CL_TIME DESC");

            if (list1 == null || list1.size() <= 0) {
                ll_root.setVisibility(View.GONE);
                tv_tjbg_no_data.setVisibility(View.VISIBLE);
                tv_tjbg_no_data.setText("暂无人体成分体检数据");
            } else {
                ll_root.setVisibility(View.VISIBLE);
                tv_tjbg_no_data.setVisibility(View.GONE);
                SBCL_DATA sbclData = list1.get(0);
                FmModel pwBean = GsonUtils.fromJson(sbclData.getCL_VALUE(), FmModel.class);
                tv_height.setText(pwBean.getHeight());
                setText(tv_height, pwBean.getHeight());
                setText(tv_weight, pwBean.getWeight());
                setText(tv_bmi, pwBean.getBmi());
                setText(tv_tzfl, pwBean.getFm());
                setText(tv_yxsy, pwBean.getFp());
                setText(tv_nzzfdj, pwBean.getVfal());
                setText(tv_tsfl, pwBean.getTbwc());
                setText(tv_sm, pwBean.getSm());
                setText(tv_ecf, pwBean.getEcf());
                setText(tv_icf, pwBean.getIcf());
                setText(tv_proteinRate, pwBean.getProteinRate());
                setText(tv_bmr, pwBean.getBmr());
                setText(tv_ewr, pwBean.getEwr());
                setText(tv_bodyScore, pwBean.getBodyScore());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void setText(TextView textView, String value) {
        if (!TextUtils.isEmpty(value)) {
            textView.setText(value);
        } else {
            textView.setText("");
        }
    }

}
